/**
 *
 * by littlefean
 */
window.onload = function () {
    let inputFuncEle = document.querySelector(`.funcInput`);
    let startNumberEle = document.querySelector(".startNumber");
    let outputEle = document.querySelector(`.output`);
    let startBtn = document.querySelector(`.start`);
    startBtn.addEventListener("click", () => {
        let funcStr = "x =>" + replaceFuncStr(inputFuncEle.value);
        let f = eval(funcStr);

        let res = f(+startNumberEle.value);

        let i = 0;


        let ani = setInterval(() => {
            let stepAdd = Math.ceil(Math.random() * 100000 + 10000);

            for (let j = 0; j <= stepAdd; j++) {
                let resNext = f(res);
                if (resNext === res) {
                    clearInterval(ani);
                    break;
                } else {
                    res = resNext;
                }
            }

            i += stepAdd;
            outputEle.innerHTML = `迭代${i}次了:<br> ${res}`;
        }, 1);

    });
}
